<template>
  <div class="switch" @click="changeValue">
    <div class="inside" :class="value ? 'bgc-on' : 'bgc-off'">
      <div class="text" :class="value ? 'font-on' : 'font-off'">
        {{ value ? "" : "" }}
      </div>
    </div>
    <div
      class="circle"
      :class="value ? 'on' : 'off'"
      @click="changeValue"
    ></div>
  </div>
</template>

<script>
export default {
  props: {
    value: {
      default: false,
    },
  },
  data() {
    return {};
  },
  methods: {
    changeValue() {
      this.$emit("changeSwitchValue");
    },
  },
};
</script>

<style lang="less" scoped>
.switch {
  position: relative;
  width: 84px;
  height: 32px;
  border-radius: 15px;
  padding: 6px 10px;
  box-sizing: border-box;
  box-shadow: 0 0 8px 1px rgb(231, 231, 231) inset;
  background-color: #fff;
  .inside {
    position: relative;
    display: flex;
    align-items: center;
    width: 100%;
    height: 100%;
    border-radius: 15px;
    .text {
      position: absolute;
      font-size: 12px;
    }
    .font-on {
      left: 11px;
      color: blue;
    }
    .font-off {
      left: 27px;
      color: #5d5a5b;
    }
  }
  .circle {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    width: 24px;
    height: 24px;
    // border-radius: 50%;
    background-image: url("../assets/img/switch_circle.png");
    background-repeat: no-repeat;
    background-size: 100%;
    cursor: pointer;
    transition: all 0.2s;
  }

  .on {
    left: 54px;
  }
  .off {
    left: 7px;
  }
  .bgc-on {
    background-color: #409EFF;
  }
  .bgc-off {
    background-color: #C0CCDA;
  }
}
</style>
